<?php
namespace Api\Controller;
use Think\Controller;
//@session_start;
class BaseController extends Controller {
  
   public $defaultLang = 'cn';
   public $tplName = NULL;
   public $webConfig = array();
   public $htmlPower = NULL;
   public $member = NULL;
   
   public function _initialize(){
	   	header('Content-Type:text/html;charset=utf-8');	
//              $this->$nowtime= strtotime(date("Y-m-d,H:i:s",time()));	
//		$this->$version=I('version')?I('version'):1;
//		//$this->inid_arr=array("228","3382","3381","3380","3379","3378");
//		$this->inid_arr=array("22108");	
                
                
                
//        if(!$this->is_login()){
//             returnApiresult('1','请先登录');exit;
//           }
//          
                
//            $token  = I('token');
//           // $token = 'e10adc3949ba59abbe56e057f20f883e';
//            if(!$this->is_token($token)){
//                returnApiresult('1','请您正规登录操作');exit;
//             }
                
   }
         
   
    public function is_token($toke){
       $res =  M('member')->where('token="'.$toke.'"')->find();
                
            if( $res){
                return true;
            }else{
                return false;
            }
       }
       
       
   
         public function is_login(){
            if($_SESSION['admin_user_id']){
                return true;
            }else{
                return false;
            }
       }
	
   
   
	public  function writelog($str)   //测试写入日志
	{
	$open=fopen(__PHYSICS__.'/log/'.date("Y-m-d",time()).".txt","a+" );
	fwrite($open,$str);
	fclose($open);
	} 
	
	
	public	function writelog_name($str,$log)   //测试写入日志
	{
	$open=fopen(__PHYSICS__.'/log/'.date("Y-m-d",time()).$log.".txt","a+" );
	fwrite($open,$str);
	fclose($open);
	} 
	

	public function writelog_alipay($str)   //测试写入日志
	{
	$open=fopen(__PHYSICS__.'/log/'.date("Y-m-d",time())."alipay.txt","a+" );
	fwrite($open,$str);
	fclose($open);
	} 
   
	public function up_down( $id , $arr , $flag){
			
			$arr_key_max = count($arr)-1;
			$id_key = array_search($id,$arr);	
			if($flag=="up"){
			  $uid =  $id_key==0?false:$arr[$id_key-1];
			  return $uid;
			}
			if($flag=="down"){
			  $did =  $id_key==$arr_key_max?false:$arr[$id_key+1];
			  return $did;
			}
	}
	
	
	public function baseValid(){
	    $config = require( __PHYSICS__."/Common/Conf/valid_index.php");
		//$config['codeSet']='0123456789';
		if(!$config['codeSet'])unset($config['codeSet']);
		if(!$config['zhSet'])unset($config['zhSet']);
	
		$Verify = new \Think\Verify($config);
		$Verify->entry();
	}
	
	public function bascCheckValid($valid,$mobile){
	
	        $mwhere=array('sms_mobile'=>(int)$mobile);
			$sms_mobile=M_G('code')->where($mwhere)->getField("sms_mobile");
			$sms_code=M_G('code')->where($mwhere)->getField("sms_code");
			
	        if(empty($mobile)){  return false; }
	        if(empty($valid)){  return false; }
			//if(session('sms_code')=="") return false; 
			if((int)$sms_code==(int)$valid && (int)$sms_mobile==(int)$mobile ){
			return true;
			}else{
			return false;
			}
	}
	
	public  function diffDate($date1,$date2){    //计算两个时间差
	if(strtotime($date1)>strtotime($date2)){  
	$tmp=$date2;  
	$date2=$date1;  
	$date1=$tmp;  
	}  
	list($Y1,$m1,$d1,$H1,$i1)=explode('-',$date1);  
	list($Y2,$m2,$d2,$H2,$i2)=explode('-',$date2);  
	$Y=$Y2-$Y1;  
	$m=$m2-$m1;  
	$d=$d2-$d1;  
	$H=$H2-$H1; 
	$i=$i2-$i1; 
	if($d<0){  
	$d+=(int)date('t',strtotime("-1 month $date2"));  
	$m--;  
	}  
	if($m<0){  
	$m+=12;  
	$y--;  
	} 
	
	if($Y>0){
	$info=$Y."年前";
	}else if($m>0){
	$info=$m."月前";
	}else if($d>0){
	$info=$d."天前";
	}else if($H>0){
	$info=$H."小时前";
	}else if($i>0){
	$info=$i."分钟前";
	}else{
	$info="1分钟前";	
	}
	return $info;  
	} 
	
	
	public  function birthday($birthday){    //生日换成成年龄
	$age = strtotime($birthday); 
	if($age === false){ 
	return false; 
	} 
	list($y1,$m1,$d1) = explode("-",date("Y-m-d",$age)); 
	$now = strtotime("now"); 
	list($y2,$m2,$d2) = explode("-",date("Y-m-d",$now)); 
	$age = $y2 - $y1; 
	if((int)($m2.$d2) < (int)($m1.$d1)) 
	$age -= 1; 
	
	if($age<0){  return  "";  }
	
	return (string)$age."岁"; 
	} 
   
	public function check_citycode($city_code){    //anroid
			//$region_id=M('region')->where(" region_name='".$city."' ")->getField('region_id');
	        return $city_code?(int)$city_code:"";						
	}
	
	public function check_ios_citycode($city){    //匹配mysql的 城市代码IOS
	        $city=urldecode($city);
			$city_code=M('baidu_city')->where("city_name='".$city."' ")->getField('city_code');
	        return $city_code?(int)$city_code:"";						
	}
	
	
	public function classone($id,$deptha){     //返回一级类
	
	$depth=M('in_class')->where("id=".$id)->getField('depth');
	switch ($depth){
		case 0:
			 return $id;
			break;
		case 1:
			 $oneid=M('in_class')->where("id=".$id." and depth=1")->getField('parent_id');
			 return $oneid;
			break;
		case 2:
			 $oneid=M('in_class')->where("id=".$id." and depth=2")->getField('parent_id');
			 $twoid=M('in_class')->where("id=".$oneid." and depth=1")->getField('parent_id');
			return $twoid;
			break;
	   } 
	}

	public function imgsave($topfile,$pname,$picdata,$delpic){   //图片存储

		$imgDir = $topfile.'/'.$pname.'/'.date("Y",time()).date("m",time()).'/';  //头像存储路径
		$path=__GUPLOAD__.$topfile.'/'.$pname.'/'.date("Y",time()).date("m",time());
		$filename=Data16to2name();     //图片重新命名 
		if(!file_exists($path)){
         mkdir($path,0777);
        }                       
        file_put_contents(__GUPLOAD__.$imgDir.$filename.'.jpg',$picdata);//写入文件中
		if(!empty($delpic)){
		$ndelpic=__GUPLOAD__.$delpic;
		if(file_exists($ndelpic)){ @unlink($ndelpic); } //删除原图  
		}
		$data= $imgDir.$filename.'.jpg';
		return  $data; 
}

     //微信未获取成功头像二次生产
	public function imgsave_weixin($topfile,$pname,$picdata,$delpic){   //图片存储
	
		if(!empty($delpic)){
		$ndelpic=__GUPLOAD__.$delpic;
		if(file_exists($ndelpic)){ @unlink($ndelpic); } //删除原图  
		}
		 $this->writelog_name($ndelpic,"index4");          
        file_put_contents(__GUPLOAD__.$delpic,$picdata);//写入文件中
		$data= $delpic;
		
		$this->writelog_name($delpic,"index3");
		
		return  $data; 
}


	public function imgsave_more($topfile,$pname,$picdata,$delpic){   //图片存储

		$imgDir = $topfile.'/'.$pname.'/'.date("Y",time()).date("m",time()).'/';  //头像存储路径
		$path=__GUPLOAD__.$topfile.'/'.$pname.'/'.date("Y",time()).date("m",time());
		$filename=Data16to2name();     //图片重新命名 
		if(!file_exists($path)){
         mkdir($path,0777);
        }                      
        file_put_contents(__GUPLOAD__.$imgDir.$filename.'.jpg',$picdata);//写入文件中
		if(!empty($delpic)){
		$ndelpic=__GUPLOAD__.$delpic;
		if(file_exists($ndelpic)){ @unlink($ndelpic); } //删除原图  
		}
		$data= date("Y",time()).date("m",time()).'/'.$filename.'.jpg';
		return  $data; 
     }
	 
	 
	public function del_uploadpic($topfile,$pname,$picdata,$delpic){   //图片存储
		if(!empty($delpic)){
		$ndelpic=__GUPLOAD__.$topfile.'/'.$pname.'/'.$delpic;
		if(file_exists($ndelpic)){ @unlink($ndelpic); } //删除原图  
		}
		return  true; 
     } 
	 
	 
	public function oss_upload($uploadname,$picdata,$delpic){    //OSS 上传文件
		vendor('Oss.autoload');
		//$picdata=$_FILES['uploadfile'];      //16进制转换成二进制
		$accessKeyId = "m30l1H7q8FGqBAhR";
		$accessKeySecret = "esDVXQpSL35LSKgMGLP1ZdXMtDON1g";
		$endpoint = "http://jdross.oss-cn-beijing-internal.aliyuncs.com";
		$bucket = "jdross";  //<您使用的存储空间名称，注意命名规范>

		$ossClient = new \OSS\OssClient($accessKeyId,$accessKeySecret,$endpoint,true);

		$path=$picdata['tmp_name'];
		$last_name=".".substr(basename($picdata['name']), strrpos(basename($picdata['name']), '.')+1);
		$newfilename=date("Y",time()).date("m",time())."/".Data16to2name().$last_name;
		$oss_path=$uploadname."/".$newfilename;
		$filePath =$path;
		try{
		$ossClient->uploadFile($bucket, $oss_path, $filePath);
		} catch(OssException $e) {
		printf(__FUNCTION__ . ": FAILED\n");
		printf($e->getMessage() . "\n");
		return;
		}
		
		if(!empty($delpic)){$ossClient->deleteObject($bucket,$delpic); } //删除原始文件
		return $oss_path;

   } 
   
   	public function oss_upload_video($uploadname,$picdata,$delpic){    //OSS 上传文件
		vendor('Oss.autoload');
		//$picdata=$_FILES['uploadfile'];      //16进制转换成二进制
		$accessKeyId = "m30l1H7q8FGqBAhR";
		$accessKeySecret = "esDVXQpSL35LSKgMGLP1ZdXMtDON1g";
		$endpoint = "http://jdross.oss-cn-beijing-internal.aliyuncs.com";
		$bucket = "jdross";  //<您使用的存储空间名称，注意命名规范>

		$ossClient = new \OSS\OssClient($accessKeyId,$accessKeySecret,$endpoint,true);

		$path=$picdata['tmp_name'];
		$last_name=".".substr(basename($picdata['name']), strrpos(basename($picdata['name']), '.')+1);
		$newfilename=date("Y",time()).date("m",time())."/".Data16to2name().$last_name;
		$oss_path=$uploadname."/".$newfilename;
		$filePath =$path;
		try{
		$ossClient->uploadFile($bucket, $oss_path, $filePath);
		} catch(OssException $e) {
		printf(__FUNCTION__ . ": FAILED\n");
		printf($e->getMessage() . "\n");
		return;
		}
		
		$target_path  = __GUPLOAD__;//接收文件目录 
		$target_path =$target_path."temp/".str_replace('/','',$newfilename);  
		if(move_uploaded_file($picdata['tmp_name'],$target_path)) {  
		//$xml="The file ".  basename( $_FILES['uploadedfile']['name']). " has been uploaded";  
		}  else{  
		//$xml="There was an error uploading the file, please try again!" . $_FILES['uploadedfile']['error'];  
		}  


		return $oss_path;

   } 
   
   	public function oss_upload_del($delpic){    //OSS 上传文件
		vendor('Oss.autoload');
		//$picdata=$_FILES['uploadfile'];      //16进制转换成二进制
		$accessKeyId = "m30l1H7q8FGqBAhR";
		$accessKeySecret = "esDVXQpSL35LSKgMGLP1ZdXMtDON1g";
		$endpoint = "http://jdross.oss-cn-beijing-internal.aliyuncs.com";
		$bucket = "jdross";  //<您使用的存储空间名称，注意命名规范>

		$ossClient = new \OSS\OssClient($accessKeyId,$accessKeySecret,$endpoint,true);
		if(!empty($delpic)){$ossClient->deleteObject($bucket,$delpic);
		   
			$temp_file = str_replace('/','',$delpic);
			$is_file="./temp/".$temp_file;
			if(file_exists($is_file)){  @unlink ($is_file);   }
			
				
		
		 } //删除原始文件
		return 1;

   } 
   
   
		public	function oss_view($object)
		{
		if(!$object){   return  ""; }
		if(strstr($object,"user/pic")){
		$url=__VUPLOAD__.$object;
		}else{
		$url=__LOADWWW__."Api.php/Get/fileview?url=".$object;
		}
		return  $url;
		
		}
		public	function oss_view_z($object)
		{
		if(!$object){   return  ""; }
		$url=__LOADWWW__."Api.php/Get/fileview?url=".$object;
		return  $url;
		
		}
		
		public	function oss_view_timepic($object)
		{
		if(!$object){   return  ""; }
		if(strstr($object,"linepic")){
		$url=__LOADWWW__."Api.php/Get/fileview?url=".$object;
		}else{
		$url=__VUPLOAD__."user/dtpic/".$object;
		}
		return  $url;
		
		}
		
		public	function oss_view_myphoto($object)
		{
		if(!$object){   return  ""; }
		$url=__LOADWWW__."Api.php/Get/fileview?url=".$object;
		return  $url;
		
		}
		

   		public	function oss_view_video($object)
		{
		     if(!$object){   return  ""; }
		    $temp_file = str_replace('/','',$object);
		
			$is_file="./temp/".$temp_file;	
			if(file_exists($is_file)){
		       return  __LOADWWW__."temp/".$temp_file;
			 //return 1;
		    }else{
			//$object=I('url');
			vendor('Oss.autoload');
			$accessKeyId = "m30l1H7q8FGqBAhR";
			$accessKeySecret = "esDVXQpSL35LSKgMGLP1ZdXMtDON1g";
			$endpoint = "http://jdross.oss-cn-beijing-internal.aliyuncs.com/";
			$bucket = "jdross";  //<您使用的存储空间名称，注意命名规范
			$ossClient = new \OSS\OssClient($accessKeyId,$accessKeySecret,$endpoint,true);
			$localfile = "temp/".$temp_file;
			$options = array(
				"fileDownload" => $localfile,
			);
			try{
				$ossClient->getObject($bucket, $object, $options);
			} catch(OssException $e) {
				return ;
			}
		      return  __LOADWWW__."temp/".$temp_file;
		   }

		}
		

	    	 public	function oss_file_down($object)
		{
		    
		    $temp_file = str_replace('/','',$object);
		
			$is_file="./temp/".$temp_file;	
			if(file_exists($is_file)){
		     return true;
			 //return 1;
		    }else{
			//$object=I('url');
			vendor('Oss.autoload');
			$accessKeyId = "m30l1H7q8FGqBAhR";
			$accessKeySecret = "esDVXQpSL35LSKgMGLP1ZdXMtDON1g";
			$endpoint = "http://jdross.oss-cn-beijing-internal.aliyuncs.com/";
			$bucket = "jdross";  //<您使用的存储空间名称，注意命名规范
			$ossClient = new \OSS\OssClient($accessKeyId,$accessKeySecret,$endpoint,true);
			$localfile = "temp/".$temp_file;
			$options = array(
				"fileDownload" => $localfile,
			);
			try{
				$ossClient->getObject($bucket, $object, $options);
			} catch(OssException $e) {
				return true;
			}
			
		    return  true;
	
		   }
      //   return  "http://www.judaren.com.cn/jdrapia/temp/".$filename;

		}
	 
	    
	public function retun_guoqitime($result,$addtime){
   		   switch ($result){
				case 0:
					return date('Y-m-d H:i',strtotime("+12 hour", $addtime));	
					break;
				case 1:
					 return date('Y-m-d H:i',strtotime("+1 day", $addtime)); 
					break;
				case 3:
					 return date('Y-m-d H:i',strtotime("+3 day", $addtime)); 
					break;
				case 7:
					 return date('Y-m-d H:i',strtotime("+1 week", $addtime)); 
					break;
				default:
				     return date('Y-m-d H:i',strtotime("+12 hour", $addtime));
			} 
   
    }
	
	public function retun_guoqi($result,$addtime){
	 
   		   switch ($result){
				case 0:
					return (string)0;	
					break;
				case 1:
					return  time()>strtotime("+1 day",$addtime)?(string)1:(string)0; 
					break;
				case 3:
				    return  time()>strtotime("+3 day",$addtime)?(string)1:(string)0; 
					break;
				case 7:
				    return time()>strtotime("+1 week",$addtime)?(string)1:(string)0; 
					break;
				default:
				     return (string)0;
			} 
   
    }	
	



	public function retun_leve($Admintype=0){  //等级图标
	    $levepic=__VUPLOAD__."grade/vip_icon".$Admintype.".png";
	    return $levepic;

    }	
	
	
	public function del_mogo_code($mobile=null){    /*删除临时验证*/
			  $del['where']=array('sms_mobile'=>(int)$mobile);
			  M_G("code")->delete($del);
	          return true;
    }
	
	
	public function mapdis($id,$mapx,$mapy,$table){    //查询定位距离
		 
		 if(empty($mapx)){  return 0; }
		 if(empty($mapy)){  return 0; }
		 if(empty($id)){  return 0; }
	     $arr=M_G('skill')->execute("db.runCommand({geoNear:'$table', near:[$mapx,$mapy], num:1, spherical:true, distanceMultiplier:6378 , query:{ '_id':ObjectId('$id') } })");
		 return $arr['results'][0]['dis']?number_format($arr['results'][0]['dis'],2,'.',''):'0.00';
		 
	}
	
	 public function retunr_bigyue($small){    /*返回大写月*/
			  $big= array('01'=>"一",'02'=>"二",'03'=>"三",'04'=>"四",'05'=>"五",'06'=>"六",'07'=>"七",'08'=>"八",'09'=>"九",'10'=>"十",'11'=>"十一",'12'=>"十二"); 
	          return $big[$small];
    }
	
	
	public function string_foreach($arr) 
		{
			if (!is_array ($arr)) 
			{
				return null;
			}
			foreach ($arr as $key => $val ) 
			{
				if (is_array ($val)) 
				{
					$newarr[$key]=$this->string_foreach($val);
				} 
				else 
				{
					$newarr[$key]=(string)$val;	
				}
			}
			return $newarr;
		}


	public function hx_send_txt($from_uid,$to_uid,$msg){   //环信信息文本提醒发送
		  $hx_from_user['nickname']=M('member_info')->where('mid=1')->getField('nickname'); 
		  $hx_from_user['pic']=__VUPLOAD__.M('member_info')->where('mid=1')->getField('pic'); 
		 // $hx_from_user='admin';
		  $hx_to_user=M('member_info')->where('mid='.$to_uid)->getField('hx_name'); 
		  $Hxclass = new \Myself\Hxcall; 
		  $data=$Hxclass->hx_send($hx_from_user,$hx_to_user,$msg);  //环信发送文本消息
		  $info= json_decode($data,true); 
		  return $info;
	}

	
	public function hx_send_pt($from_uid,$to_uid,$msg){   //环信信息文本提醒发送
		  $hx_from_user['nickname']=M('member_info')->where('mid='.$from_uid)->getField('nickname'); 
		  $hx_from_user['pic']=$this->oss_view(M('member_info')->where('mid='.$from_uid)->getField('pic')); 
		 // $hx_from_user='admin';
		  $hx_to_user=M('member_info')->where('mid='.$to_uid)->getField('hx_name'); 
		  $Hxclass = new \Myself\Hxcall; 
		  $data=$Hxclass->hx_send_pt($hx_from_user,$hx_to_user,$msg);  //环信发送文本消息
		  $info= json_decode($data,true); 
		  return $info;
	}
	
    public function return_check_name($json){ 

					$dataone=str_replace('&quot;',"",$json);
					$dataone=json_decode($dataone,true); 

						foreach($dataone as $key=>$item){
						if($key>0){ $info.="/";	}
						$info.=M('industry_check')->where("ck_id=".$item)->getField('ck_name');
					
						}
				
				return $info?$info:"";
												
	     }
		 
	public function return_check_rate($json){ 	 
		 	        $array=json_decode($json);
			foreach($array as $key=>$item){
			$info=(array)$item;
				if($info['ck_id_group']=='26'){
					if($info['ck_id_child']==1){
					$data="（一次性）";
					}else if($info['ck_id_child']==2){
					$data="（一周）";
					}else if($info['ck_id_child']==3){
					$data="（一月）";
					}else{
					$data="";
					}
				}
			}
			 return $data; 
	
	  }	
	  
    public function hx_is_parr($p_arrt=null,$p_arrs=null,$p_numt=null,$p_nums=null){   //匹配服务范围
	
			if($p_arrs){
			$fruit1 = json_decode($p_arrt, true);
			$fruit2 = json_decode($p_arrs, true);
			$intersection = array_intersect($fruit1, $fruit2);
			if($p_numt && $p_numt!="[ ]"){
			$fruit3 = json_decode($p_numt, true);
			$fruit4 = json_decode($p_nums, true);
			$intersection2 = array_intersect($fruit3, $fruit4);			
			}
			if($intersection){
			if($p_numt && $p_numt!="[ ]"){
			  if($intersection2){ return true; }else{  return false;  }
			}else{

			return true; 
			}
			 }

			}else{
			return false;
			}
			
	}
	
			
	public function add_tg_user_mobile($mobile){
		 M('user_tg_member')->where("mobile='".$mobile."'")->setField('status',3); //记录注册APP
		 return true;

	}
	
	
			
	public	function get_duobao_num($num1, $num2){    //计算百分比，夺宝进度
			$num = false;
			if(is_numeric($num1) && is_numeric($num2)) {
			$num = ( $num1 / $num2 ) * 100 ;
				if($num1>0 && $num<1){
				return (string)1;
				}else{
				return (string)round($num, 0);
				}
			} else {
			return (string)round($num, 0);
			}
	}	
	
	
   public	function get_int_wan_num($num){    //计算百分比，夺宝进度
				return (string)($num);

	}
	
   public	function add_everyday_jifen($uid){    //每日登录：+2积分/日限一次	
		         if($uid){
						if(date("Ymd")!=M("member_info")->where('mid='.$uid)->getField('jifen_everyday')){
						M("member_info")->where('mid='.$uid)->setInc('jifen_money',2); //每日登录：+2积分/日限一次
						M("member_info")->where('mid='.$uid)->setField('jifen_everyday',date("Ymd")); //更新当天时间用于一天一次+2积分
						$this->add_jifen_log($uid,2,'每日登录赠送积分',0,0);
						}
				 }	
				 return true;	
			
	}	
	
		  //积分日志
		
   public function add_jifen_log($uid,$jifen,$desc,$type,$ob_id=0){
			$addlogdata["id"]=Getmysql_Idstr(6);
			$addlogdata['user_id']=$uid;
			$addlogdata['jifen_money']=$jifen;  
			$addlogdata['change_type']=$type;  //类型 0 增加积分 1 消费积分 
			$addlogdata['change_desc']=$desc;  //变动说明
			$addlogdata["ob_id"]=$ob_id; //变动源头ID
			$addlogdata['addtime']=time();
			$request=M_S('jifen_log')->add($addlogdata);
			return true;
		
		}

		 
		//返回多图列表
   public function return_morepic_data($ids,$type){

				
			   // $ids=(int)"201611280349099175";
			//	$type=(int)2;
			    if($type==1){
			    $cs_state=M_S("skill")->where("id=".$ids)->getField('cs_morepic');
				}
				
			    if(empty($cs_state)){
			    $ids=(int)$ids;
				$type=(int)$type;
				//$where['where']['ob_type']=(int)2;
				$info = M_G("timeline")->where(array('ob_id'=>$ids,'ob_type'=>$type))->find();
                $picdata=$info['content_img'];
				if(!empty($picdata)){
				foreach($picdata as $key=>$item){
				 if($key<3){  //只查询三个
				$data_morepic[$key]=$this->oss_view_timepic($item);
				 }
				}
				$data=$data_morepic;
				}else{
				$data=array();
				}
				
				}else{
				
				$picdata=explode(",",$cs_state);
				
				if(!empty($picdata)){
				foreach($picdata as $key=>$item){
				$data_morepic[$key]=__VUPLOAD__."skill/".$item;
				}}
				
				$data=$data_morepic?$data_morepic:array();
				
				}
	
				$num=count($picdata)>3?(count($picdata)-3):0;
			    return array($data,$num);
		
		}	
				
		
		//返回多图详情
   public function return_morepic_data_view($ids,$type){
					   
		   		//$ids=(int)"201611280349099175";
				//$type=(int)2;
			    $ids=(int)$ids;
				$type=(int)$type;
				
				if($type==1){
			    $cs_state=M_S("skill")->where("id=".$ids)->getField('cs_morepic');
				}
				
			   if(empty($cs_state)){	
				//$where['where']['ob_type']=(int)2;
				$info = M_G("timeline")->where(array('ob_id'=>$ids,'ob_type'=>$type))->find();
                $picdata=$info['content_img'];
				if(!empty($picdata)){
				foreach($picdata as $key=>$item){
				 // if($key<3){  //只查询三个
				$data_morepic[$key]=$this->oss_view_timepic($item);
				 // }
				}
				$data=$data_morepic;
				}else{
				$data=array();
				}
				
				}else{
				
				$picdata=explode(",",$cs_state);
				
				if(!empty($picdata)){
				foreach($picdata as $key=>$item){
				$data_morepic[$key]=__VUPLOAD__."skill/".$item;
				}}
				
				$data=$data_morepic?$data_morepic:array();
				
				}
				
	            
				$num=count($picdata)>3?(count($picdata)-3):0;
			    return array($data,$num);
		
		}			
	//返回URL图片	
  public function reg_pic_file($url){	
		
		// 设置运行时间为无限制
		set_time_limit ( 0 );
		
		$url = trim ( $url );
		$curl = curl_init ();
		// 设置你需要抓取的URL
		curl_setopt ( $curl, CURLOPT_URL, $url );
		// 设置header
		//curl_setopt ( $curl, CURLOPT_HEADER, 1 );
		// 设置cURL 参数，要求结果保存到字符串中还是输出到屏幕上。
		curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );
		// 运行cURL，请求网页
		$file = curl_exec ( $curl );
		// 关闭URL请求
		curl_close ( $curl );	
		////创建数据流上下文
		return $file;
		}
		
	public	function utf8_strlen($string = null) {   //计算中文长度
	// 将字符串分解为单元
	preg_match_all("/./us", $string, $match);
	// 返回单元个数
	return count($match[0]);
	}		
		
 
}